from pymongo import MongoClient
client=MongoClient("127.0.0.1:27017")
db = client.get_database("test")
db.places.insert_many(
[
{
"name": "Central Park",
"location": { "type": "Point", "coordinates": [-73.97, 40.77]},
      "category": "Parks"
},
{
"name": "Sara D. Roosevelt Park",
"location": { "type": "Point", "coordinates": [-73.9928, 40.7193]},
"category": "Parks"
},
{
"name": "Polo Grounds",
"location": { "type": "Point", "coordinates": [-73.9375, 40.8303]},
"category": "Stadiums"
}
])
db.places.create_index([("location","2dsphere")])
result = db.places.find({"location": {"$near": {"$geometry":
                    { "type": "Point",  "coordinates": [ -73.9667, 40.78 ]},
                   "$minDistance": 1000,"$maxDistance": 5000}}
                })
for i in result:
    print(i)
db.client.close()
